/*
This file is part of Jumpers.

Jumpers is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Jumpers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Jumpers.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.chaoticengine.cgll.entity.component.move;

//~--- non-JDK imports --------------------------------------------------------


import org.newdawn.slick.GameContainer;
import org.newdawn.slick.geom.Vector2f;

//~--- JDK imports ------------------------------------------------------------
import org.newdawn.slick.state.StateBasedGame;

import org.simpleframework.xml.Element;

/**
 * The SimpleMovementComponent is designed to model simple straight-line movement
 * at a constant speed (without player or AI intervention). It will typically be
 * used for things such as bullets.
 *
 * @author Matt v.d. Westhuizen
 *
 */
public class SimpleMovementComponent extends BasicMovementComponent {
    public Vector2f direction = new Vector2f();
    public float speed = 0.0f;

    public SimpleMovementComponent() {
        super();
    }

    @Override
    public void update(GameContainer gc, StateBasedGame sb, int delta) {
        super.update(gc, sb, delta);

        this.accelerate(direction, speed);
    }

    @Element(name="direction")
    public final Vector2f getDirection() {
        return (direction.copy().scale(speed));
    }

    @Element(name="direction")
    public void setDirection(Vector2f vel) {
        this.direction = vel.copy().getNormal();
    }

    @Element(name="speed")
    public float getSpeed() {
        return(this.speed);
    }

    @Element(name="speed")
    public void setSpeed(float s) {
        this.speed = s;
        this.maxV = s;
    }
}
